/*
 * @Author: szx
 * @Date: 2022-03-07 13:46:20
 * @LastEditTime: 2022-03-07 13:51:40
 * @Description:
 * @FilePath: \leetcode\500-599\530\530_2.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
 var getMinimumDifference = function (root) {
    let prev = null;
    let res = Infinity;
    const dfs = (root) => {
        if(!root) return;
        if (root.left) dfs(root.left);
        if (prev) {
            
            res = Math.min(root.val - prev.val, res);
        }
        prev = root;
        if (root.right) dfs(root.right);
    };
    dfs(root)
    return res;
};
